package obstaculos;

import org.anddev.andengine.entity.sprite.AnimatedSprite;
import org.anddev.andengine.entity.sprite.Sprite;
import org.anddev.andengine.opengl.texture.TextureManager;
import org.anddev.andengine.opengl.texture.TextureOptions;
import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.anddev.andengine.opengl.texture.region.TextureRegion;

import android.content.Context;

public class BolaDeFerro extends Obstaculo {
	
	private BitmapTextureAtlas mapaDeTexturas;
	private TextureRegion textura;

	public BolaDeFerro(int x, int y, Context contexto, TextureManager tm) {
		this.x = x;
		this.y = y;
		largura = 64;
		altura = 32;
		
		mapaDeTexturas = new BitmapTextureAtlas(128, 512, TextureOptions.BILINEAR);
		BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");
		textura = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mapaDeTexturas, contexto, "Bola de ferro.png", 0, 0);
		tm.loadTexture(mapaDeTexturas);
		
		sprite = new Sprite(x, y, textura);
	}

	@Override
	public void atualiza() {
		if(!meuGatilho.ativado){
			if(y > 0){
				y-=2;
			}
		}
		if(meuGatilho.ativado){
			if(y < 192){
				y+=8;
				meuGatilho.ativado = false;
			}
		}
	}

	@Override
	public boolean colidiuComDono(AnimatedSprite spriteDono) {
		return true;
	}

	@Override
	public void posicionaNaCena(int mapx, int mapy) {
		sprite.setPosition((int)x-mapx, (int)y-mapy);
	}
}
